import Q from 'q'
import axios from 'axios'
import envFuncs from '@/config/base'
let env = envFuncs.getParams()
import { S, U, getRequestId, mapField } from '../../lib/backend'

export default {
  getWorckbenchData ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/workbench' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getTeamRankingData ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/leader_boards' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getMemberRankingData ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/team_member_list' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getTeamData ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/team' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getMemberData ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/team/member' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getNewSignList ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/new_signing_list' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getEstimateList ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/earnings_estimate_list' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getNewTransactionList ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/transaction_order_list' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getCustomOrderList ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    // let CRM_API_HOST = ' http://rap.taobao.org/mockjsdata/18476'
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/custom_order' + '?' + U(info || {}, false)
    // let url = 'http://rap2api.taobao.org/app/mock/2717/GET//example/1514357201480'
    return axios.get(url)
  },
  getNewCustomSourceList ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/get_new_custom_source_list' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getNewCustomSecondSourceList ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/get_new_custom_second_source_list' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getNewCustomGuanHuaiAnalyzeSource ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/get_new_custom_guanhuai_analyze_source' + '?' + U(info || {}, false)
    return axios.get(url)
  },
  getNewCustomChengJiaoAnalyzeSource ({rootState}, info) {
    let CRM_API_HOST = env.CRM_API_HOST
    let url = CRM_API_HOST + '/sites/' + rootState.app.site_id + '/users/' + rootState.app.token + '/get_new_custom_chengjiao_analyze_source' + '?' + U(info || {}, false)
    return axios.get(url)
  }
}
